<?php require_once 'Master_controller.php';
class Product extends Master_controller {
	protected $_page_uri = "product";
	
	function __construct() {
		parent::__construct();
		$this->view_data['active_product'] = "current";
		$this->load->model('Product_model');
		$this->_page_uri = site_url() . $this->_page_uri;
	}
	
	function index($offset = 0) {
		$this->view_data['view'] = "product_view";
		$this->view_data['list_product'] = $this->Product_model->get_paged_list(PRODUCT_ITEM_PER_PAGE, $offset)->result();
		$this->view_data['pagination'] = $this->_render_paging($this->Product_model->count_all(), $offset, PRODUCT_ITEM_PER_PAGE);
		
		$this->render_page($this->view_data);
	}
	function filter($category = 0, $offset = 0) {
		$this->view_data['view'] = "product_view";
		$this->view_data['category'] = $category;
		$this->view_data['list_product'] = $this->Product_model->get_related_list(PRODUCT_ITEM_PER_PAGE, $offset, $category)->result();
		$this->view_data['pagination'] = $this->_render_paging($this->Product_model->count_filter($category), $offset, PRODUCT_ITEM_PER_PAGE, 'filter/'.$category, 4);
		
		$this->render_page($this->view_data);
	}
	function detail($id = 0) {
		$this->view_data['view'] = "product_detail_view";
		$product_detail = $this->Product_model->get_by_id($id)->row();;
		$this->view_data['category'] = $product_detail->category;
		$this->view_data['product_detail'] = $product_detail;
		$this->view_data['related_product'] = $this->Product_model->get_related_list(3, 0, $product_detail->category)->result();
		
		$this->render_page($this->view_data);
	}
	
	function search($text = '', $offset = 0) {
		$this->view_data['view'] = "product_view";
		$this->view_data['search_text'] = urldecode($text);
		$this->view_data['list_product'] = $this->Product_model->search(PRODUCT_ITEM_PER_PAGE, $offset, urldecode($text))->result();
		$this->view_data['pagination'] = $this->_render_paging($this->Product_model->count_search(urldecode($text)), $offset, PRODUCT_ITEM_PER_PAGE, 'search/'.$text, 4);
		
		$this->render_page($this->view_data);
	}
}